package com.muyaxuan.mail.controller.customer;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.muyaxuan.mail.common.AuthCode;

@Controller
public class AuthCodeController {
	public static String AUTH_CODE="AUTH_CODE";
	
	@RequestMapping("/verify")
	public static void getAuthCode(HttpSession session,HttpServletResponse response){
		//获取验证码
		String code = AuthCode.getAuthCode();
		//将验证码存储到session中方便后面使用
		session.setAttribute("code", code);
		//获取验证码图片
		BufferedImage img=AuthCode.getCodeImg(code);
		
		try {
			//输出页面
			ImageIO.write(img, "JPEG", response.getOutputStream());
		} catch (IOException e) {
			System.out.println("输出失败");
			e.printStackTrace();
		}	
	}
}
